/*
* test1
*/
package com.pitop.errortype.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.errortype.entity.ErrortypeLocal;
import com.pitop.errortype.service.ErrortypeLocalSV;

/**
 * 错误类型本地化 控制器
 *
 * @author test1
 */
@RestController
@RequestMapping("/errortypeLocal")
@Slf4j
@Api(value = "错误类型本地化控制器", description = "错误类型本地化控制器")
public class ErrortypeLocalCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ErrortypeLocalSV errortypeLocalSV;

    /**
     * 查询ErrortypeLocal一个详情信息
     *
     * @param id
     * @param errorTypeCode 错误类型编码
     * @param language      语言
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public ErrortypeLocal load(Long id, String errorTypeCode, String language) {
        if (id == null) {
            return null;
        }
        if (errorTypeCode == null) {
            return null;
        }
        if (language == null) {
            return null;
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSV.load(id, errorTypeCode, language);
        log.info(JSON.toJSONString(errortypeLocal));
        return errortypeLocal;
    }


    /**
     * 根据条件id查询ErrortypeLocal一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public ErrortypeLocal loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSV.loadById(id);
        log.info(JSON.toJSONString(errortypeLocal));
        return errortypeLocal;
    }

    /**
     * 根据条件errorTypeCode查询ErrortypeLocal一个详情信息
     *
     * @param errorTypeCode 错误类型编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/errorTypeCode/{errorTypeCode}")
    @ResponseBody
    public ErrortypeLocal loadByErrorTypeCode(@PathVariable String errorTypeCode) {
        if (errorTypeCode == null) {
            return null;
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSV.loadByErrorTypeCode(errorTypeCode);
        log.info(JSON.toJSONString(errortypeLocal));
        return errortypeLocal;
    }

    /**
     * 根据条件language查询ErrortypeLocal一个详情信息
     *
     * @param language 语言
     * @return BeanRet
     */
    @ApiOperation(value = "查询ErrortypeLocal一个详情信息", notes = "查询ErrortypeLocal一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "language", value = "语言", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/language/{language}")
    @ResponseBody
    public ErrortypeLocal loadByLanguage(@PathVariable String language) {
        if (language == null) {
            return null;
        }
        ErrortypeLocal errortypeLocal = errortypeLocalSV.loadByLanguage(language);
        log.info(JSON.toJSONString(errortypeLocal));
        return errortypeLocal;
    }


    /**
     * 查询ErrortypeLocal信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ErrortypeLocal信息集合", notes = "查询ErrortypeLocal信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<ErrortypeLocal> list(@RequestBody @ApiIgnore ErrortypeLocal errortypeLocal, Integer curPage, Integer pageSize) {
        Page<ErrortypeLocal> page = new Page<ErrortypeLocal>(pageSize, curPage);
        List<ErrortypeLocal> errortypeLocals = errortypeLocalSV.list(errortypeLocal, page.genRowStart(), page.getPageSize());
        int total = errortypeLocalSV.count(errortypeLocal);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return errortypeLocals;
    }


    /**
     * 查询ErrortypeLocal信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ErrortypeLocal信息集合", notes = "查询ErrortypeLocal信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<ErrortypeLocal> listByPk(Long id, String errorTypeCode, String language, Integer curPage, Integer pageSize) {
        Page<ErrortypeLocal> page = new Page<ErrortypeLocal>(pageSize, curPage);
        List<ErrortypeLocal> errortypeLocals = errortypeLocalSV.list(id, errorTypeCode, language, page.genRowStart(), page.getPageSize());
        int total = errortypeLocalSV.count(id, errorTypeCode, language);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return errortypeLocals;
    }

    /**
     * 统计ErrortypeLocal信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计ErrortypeLocal信息数量根据主键", notes = " 统计ErrortypeLocal信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String errorTypeCode, String language) {
        return errortypeLocalSV.count(id, errorTypeCode, language);
    }

    /**
     * 统计ErrortypeLocal信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计ErrortypeLocal信息数量", notes = "统计ErrortypeLocal信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "文本对照", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody ErrortypeLocal errortypeLocal) {
        return errortypeLocalSV.count(errortypeLocal);
    }


    /**
     * 创建ErrortypeLocal
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ErrortypeLocal", notes = "创建ErrortypeLocal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "文本对照", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public ErrortypeLocal build(@RequestBody @ApiIgnore ErrortypeLocal errortypeLocal) {
        errortypeLocalSV.save(errortypeLocal);
        return errortypeLocal;
    }


    /**
     * 修改ErrortypeLocal
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ErrortypeLocal", notes = "修改ErrortypeLocal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "info", value = "文本对照", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public ErrortypeLocal modify(@RequestBody @ApiIgnore ErrortypeLocal errortypeLocal) {
        errortypeLocalSV.modify(errortypeLocal);
        return errortypeLocal;
    }

    /**
     * 删除ErrortypeLocal
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ErrortypeLocal", notes = "删除ErrortypeLocal")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "errorTypeCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String errorTypeCode, String language) {
        errortypeLocalSV.delete(id, errorTypeCode, language);
        return BeanRet.create(true, "删除ErrortypeLocal成功");
    }

}
